package main

import "fmt"
import "database/sql"
import _ "mysql"

func main(){
	// connect db
	//[username[:password]@][protocol[(address)]]/dbname[?param1=value1&paramN=valueN]
	db, e := sql.Open("mysql", ":@/test?charset=utf8")
	if e != nil {
		fmt.Printf("conn error.");
		return;
	}
	defer db.Close()

	fmt.Println(db)

	// query
	rows,e := db.Query("select 4, now()")
	if e != nil {
		fmt.Printf("query error.");
		return;
	}
	fmt.Println(rows)

	// result
	i := 0
	for rows.Next() {
		i++
		var ss,s2 string
		e = rows.Scan( &ss,&s2 )
		if e == nil {
			fmt.Printf("Title: %s,%s \n", ss,s2 )
		}else{
			fmt.Printf("error")
		}
	}
	fmt.Printf("Total: %d\n" , i )
}
